import java.util.ArrayList;
import java.util.Date;

/**
 * 
 */

/**
 * @author florian
 *
 */
public class Group implements java.lang.Comparable
{
	int _ID;
	String _group_name;
	Date _creation_date;
	ArrayList<Runner> _runners;
	double _score;
	
	static int current_ID=0;
	
	public Group()
	{}
	
	public Group(String groupName, Runner runner) 
	{
		super();		
		_ID = current_ID;
		_group_name = groupName;
		_creation_date = new Date();
		_runners = new ArrayList<Runner>();
		_runners.add(runner);
		current_ID++;
	}
	
	public Group(int id, String groupName, Date creationDate, ArrayList<Runner> runners) 
	{
		super();
		_ID = id;
		_group_name = groupName;
		_creation_date = creationDate;
		_runners = runners;
		current_ID++;
	}

	public void updateScore() {
		double score = 0;
		for(int i=0;i<_runners.size();i++)
		{
			score = score + _runners.get(i)._score;
		}
		_score = score;
	}

	@Override
	public int compareTo(Object other) {
	      double score1 = ((Group) other)._score; 
	      double score2 = this._score;
	      if (score1 > score2)  return -1; 
	      else if(score1 == score2) return 0; 
	      else return 1; 
	}
	
	public String ToString()
	{
		return( _group_name + " with " + _score + " points");
	}
}
